<?php

namespace Boosen\Admin\Menus;

use Encore\Admin\Admin;
use Encore\Admin\Auth\Database\Menu;
use Encore\Admin\Extension;
use Illuminate\Routing\Router;

class Menus extends Extension
{
    /**
     * Bootstrap this package.
     *
     * @return void
     */
    public static function boot()
    {
        static::registerRoutes();

        Admin::extend('menus', __CLASS__);
    }

    /**
     * Register routes for laravel-admin.
     *
     * @return void
     */
    public static function registerRoutes()
    {
        parent::routes(function ($router) {
            /* @var \Illuminate\Routing\Router $router */
            $router->resource(
                config('menus.routes.menus', 'menus'),
                config('admin.extensions.menus.controller', 'Boosen\Admin\Menus\Controllers\MenuController')
            );

            $router->resource('{mid}/' . config('menus.routes.menu_items', 'menu_items'), 'Boosen\Admin\Menus\Controllers\MenuItemController', ['except' => ['create']]);
        });
    }

    public static function import()
    {

        parent::createMenu('Menus', 'menus', 'fa-anchor');

        parent::createPermission('Boosen menus', 'ext.menus', config('menus.routes.menus', 'menus') . '*');
    }
}
